#ifndef __MODELMANAGER_H__
#define __MODELMANAGER_H__

#include "Graphics/Renderer.h"
#include "Utils/Manager.h"
#include "Utils/Singleton.h"
#include "Utils/Array.h"
#include <map>

namespace RayFrame
{
  class DLL_DECLARE Mesh;

  typedef std::map<STRING, Mesh*>   ModelMap;
  typedef ModelMap::iterator        ModelMapIter;

  /// actually hode verties and indices data
  struct Stream {
    float *vertices;
    unsigned *indices;
    unsigned nVertices;

    int nComponents;
    AttributeType type;

    bool optimized;
  };

  struct Batch {
    unsigned startIndex;
    unsigned nIndices;
    unsigned startVertex;
    unsigned nVertices;
  };

  struct ObjMaterial {
    char *name;
    RefArray <unsigned> *indices;
  };

  class DLL_DECLARE MeshManager: public Singleton<MeshManager>, public Manager<Mesh>
  {
  public:
    MeshManager();
    ~MeshManager();

    /** Load 3ds mesh file. 
    @modelname Name used to retrive model object later
    @filename Filename can be a absolute path or relative path to resources/meshes
    **/
    Mesh* Load3ds(STRING modelname, STRING filename);
    Mesh* LoadObj(STRING modelname, STRING filename);
    void  LoadObj(STRING modelname, STRING filename, Mesh& model);

    DECL_SINGLETON(MeshManager);
  protected:
    void doLoadObj(STRING modelname, STRING filename, Mesh& model);
    void doLoadObjMaterial(STRING filename, Mesh& mesh);
  };
};

#endif